package com.gucheng.aigc.controller;


import com.gucheng.aigc.common.BaseResponse;
import com.gucheng.aigc.common.ResultUtils;
import com.gucheng.aigc.model.dto.image.ImageByAiRequest;
import com.gucheng.aigc.model.entity.User;
import com.gucheng.aigc.model.vo.ImageResponse;
import com.gucheng.aigc.service.ImageService;
import com.gucheng.aigc.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


@Slf4j
@RestController
@RequestMapping("/image")
public class ImageController {

    @Resource
    private ImageService imageService;

    @Resource
    private UserService userService;

    @Autowired
    public ImageController(ImageService imageService) {
        this.imageService = imageService;
    }

    @PostMapping("/gen")
    public BaseResponse<ImageResponse> generateImageByAi(@RequestBody ImageByAiRequest imageByAiRequest, HttpServletRequest request) {
        User loginUser = userService.getLoginUser(request);
        ImageResponse result = imageService.generateImageByAi( imageByAiRequest, loginUser);
        return ResultUtils.success(result);
    }
}